package com.tjetc.controller;

import com.tjetc.common.JsonResult;
import com.tjetc.service.AreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping("/district")
public class DistrictController {
    @Autowired
    private AreaService areaService;

    /***
     * 获取所有的pid对应下的区
     * @param id
     * @return
     */
    @RequestMapping("query/{id}")
    public JsonResult getAllProvince(@PathVariable int id){
        return areaService.getAllChildByPid(id, 3);
    }

    /***
     * 根据名称获取区的id
     * @param name
     * @return
     */
    @RequestMapping("queryid/{name}")
    public JsonResult getAllProvince(@PathVariable String name){
        return areaService.getAreaIdFromName(name, 3);
    }

    /***
     * 根据id获取区名称
     * @param id
     * @return
     */
    @RequestMapping("queryname/{id}")
    public JsonResult getProvince(@PathVariable int id){
        return areaService.getAreaById(id, 3);
    }
}
